package com.kingsoft.dc.khaos.module.spark.metadata.sink

import org.json4s.JsonAST.JObject


/**
 * Created by chengguangqing on 2019/6/10.
 */
case class SinkInfo(id: String = null,
                    name: String = null,
                    clazz: String = null,
                    engine: String = null,
                    clazz_type: String = null,
                    strategy: StrategyInfo = null) {
}

case class StrategyInfo(clazz: String = null,
                        config: JObject = null)

case class HdfsConfig(db_name: String = "",
                      table_name: String = "",
                      hdfs_sub_path: Option[String],
                      write_option: String = null,
                      filter: String = null,
                      extender: ExtenderInfo = null,
                      extract_fields: List[ExtractFieldInfo] = Nil
                     )

case class MySQLConfig(db_name: String = null,
                       table_name: String = null,
                       write_option: String = null,
                       filter: String = null,
                       IfDeleteOn: Boolean = false,
                       advanced_options: Any = null,
                       extender: ExtenderInfo = null,
                       logic_pk: List[String] = null,
                       extract_fields: List[ExtractFieldInfo] = List()
                      )

case class SqlServerConfig(db_name: String = null,
                           table_name: String = null,
                           write_option: String = null,
                           filter: String = null,
                           IfDeleteOn: Boolean = false,
                           advanced_options: Any = null,
                           extender: ExtenderInfo = null,
                           logic_pk: List[String] = null,
                           extract_fields: List[ExtractFieldInfo] = List()
                          )

case class OracleConfig(db_name: String = null,
                        table_name: String = null,
                        write_option: String = null,
                        is_delete:Option[Boolean],
                        filter:Option[String]=null,
                        advanced_options: Any = null,
                        extender: ExtenderInfo = null,
                        logic_pk: List[String] = null,
                        extract_fields: List[ExtractFieldInfo] = List()
                       )

case class OptionInfo(field: String = null,
                      data_type: String = null,
                      option: List[String] = null) {}

/*
  hive
 */
case class HiveSinkConfig(db_name: String = "",
                          table_name: String = "",
                          partition: Option[String],
                          sync_mode: Option[String],
                          write_option: Option[String],
                          advanced_options: JObject = null,
                          extender: ExtenderInfo = null,
                          extract_fields: List[ExtractFieldInfo] = Nil
                         )

case class HiveAdvancedOptions(
                                data_split: DateSplitInfo = null,
                                commit_recods: Option[String]
                              )

case class DateSplitInfo(on_off: Boolean = false,
                         nums: String = "")

case class ExtenderInfo(auth: ExtendedAuth = null,
                        meta: ExtendedMeta = null)

case class ExtendedAuth(clazz: String = "",
                        params: JObject = null)

case class ExtendedMeta(clazz: String = "",
                        params: JObject = null)

case class ExtendedAuthParams(ds_type: String = "",
                              ds_id: String = "",
                              ds_name: String = "",
                              project_id: String = "",
                              defaultDs: Option[Boolean])

case class ExtendedMetaParams(ds_type: String = "",
                              ds_id: String = "",
                              ds_name: String = "",
                              project_id: String = "",
                              defaultDs: Option[Boolean])

case class ExtractFieldInfo(field: String = "",
                            data_type: String = "",
                            length: Option[String],
                            from_field: String = "",
                            no_check: Option[Boolean] = Option(false),
                            field_props: ExtractFieldProps = null)

case class ExtractFieldProps(not_null: Option[String],
                             key_type: Option[String],
                             default_value: String,
                             is_partition: Option[Boolean],
                             partition_info: Option[String])

/*
  hbase
 */
case class HBaseConfig(db_name: String = null,
                       table_name: String = null,
                       write_option: Option[String] = null,
                       advanced_options: HBaseAdvancedOption = null,
                       extender: ExtenderInfo = null,
                       extract_fields: List[ExtractFieldInfo] = List()
                      )

case class HBaseAdvancedOption(
                              )

case class HBaseRKOption(colName: String = null,
                         var data_type: Option[String] = Option(""),
                         `type`: String = null
                        )

/*
cos
 */
case class CosSinkConfig(db_name: String = "",
                         table_name: String = "",
                         file_name: Option[String],
                         write_option: String = "",
                         add_head: String = "",
                         advanced_options: Any = null,
                         extender: ExtenderInfo = null,
                         extract_fields: List[ExtractFieldInfo] = Nil
                        )

/*
    redis
 */
case class RedisSinkConfig(db_name: Option[String] = null,
                           table_name: String = null,
                           write_option: Option[String] = null,
                           key_mode: RedisKeyMode = null,
                           value_mode: RedisValueMode = null,
                           advance_options: RedisAdvancedOption = null,
                           extender: ExtenderInfo = null,
                           extract_fields: List[ExtractFieldInfo] = List()
                          )

case class RedisAdvancedOption(
                              )

case class RedisKeyMode(key_index: Option[List[String]] = Option(List()),
                        key_delimiter: Option[String] = Option(null),
                        ttl_mode: Option[RedisTtlMode] = Option(null)
                       )

case class RedisTtlMode(on_off: Option[String] = Option("false"),
                        ttl: Option[String] = null
                       )

case class RedisValueMode(`type`: Option[String] = null,
                          write_mode: Option[String] = null,
                          value_mode: Option[String] = null,
                          value_delimiter: Option[String] = null,
                          inner_key: Option[String] = null
                         )

/*
  mpp
 */
case class MppSinkConfig(db_name: String = null,
                         table_name: String = null,
                         sub_table: SubTabelInfo = null,
                         write_option: String = null,
                         advance_options: Any = null,
                         extender: ExtenderInfo = null,
                         extract_fields: List[ExtractFieldInfo] = List()
                        )

case class SubTabelInfo(on_off: String = "false",
                        suffix: String = "")

/*
es
 */
case class ESSinkConfig(db_name: String = null,
                        table_name: String = null,
                        doc_id: JObject = null,
                        write_option: Option[String],
                        advanced_options: Any = null,
                        extender: Option[ExtenderInfo] = null,
                        extract_fields: List[EsExtractFieldInfo] = List()
                       )

case class EsExtractFieldProps(not_null: Option[String] = null,
                               key_type: String = "",
                               default_value: String = "")

case class EsExtractFieldInfo(field: String = "",
                              data_type: String = "",
                              length: Option[String],
                              from_field: String = "",
                              field_props: EsExtractFieldProps = null)


case class PatternRule(stitching_fields: List[String] = List(),
                       stitching_mode: String = "")

/*
influx sink
 */
case class InfluxSinkConfig(db_name: String = null,
                            table_name: String = null,
                            write_option: String = null,
                            advanced_options: Any = null,
                            extender: Option[ExtenderInfo] = null,
                            extract_fields: List[InfluxExtractFieldInfo] = List()
                           )

case class InfluxExtractFieldInfo(field: String = "",
                                  data_type: String = "",
                                  field_type: String = "",
                                  length: Option[String],
                                  from_field: String = "",
                                  field_props: ExtractFieldProps = null)

/*
gp sink
 */
case class PGSqlSinkConfig(db_name: String = null,
                           table_name: String = null,
                           write_option: String = null,
                           advance_options: Any = null,
                           extender: ExtenderInfo = null,
                           extract_fields: List[ExtractFieldInfo] = List())

/*
gp sink
 */
case class GreenPlumSinkConfig(db_name: String = null,
                               table_name: String = null,
                               sub_table: SubTabelInfo = null,
                               write_option: String = null,
                               advance_options: Any = null,
                               extender: ExtenderInfo = null,
                               extract_fields: List[ExtractFieldInfo] = List())

/*
KDW_for_HAWQ sink
 */
case class HAWQSinkConfig(db_name: String = null,
                          table_name: String = null,
                          sub_table: SubTabelInfo = null,
                          write_option: String = null,
                          advance_options: Any = null,
                          extender: ExtenderInfo = null,
                          extract_fields: List[ExtractFieldInfo] = List())

/*
ks3
 */

case class Ks3Config(db_name: String = "",
                     table_name: String = "",
                     file_name: Option[String],
                     write_option: String = "",
                     add_head: String = "",
                     advanced_options: Any = null,
                     extender: ExtenderInfo = null,
                     extract_fields: List[ExtractFieldInfo] = Nil
                    )

/*
phoenix sink
 */
case class PhoenixConfig(db_name: String = null,
                         table_name: String = null,
                         write_option: Option[String] = null,
                         advanced_options: PhoenixAdvancedOption = null,
                         extender: ExtenderInfo = null,
                         extract_fields: List[ExtractFieldInfo] = List()
                        )

case class PhoenixAdvancedOption(var parallelism: Option[PhoenixWriteParall])

case class PhoenixWriteParall(var on_off: Option[Boolean] = Option(false), var write_parall: Option[Int] = Option(-1))

/*
kafka sink
 */
case class KafkaSinkConfig(db_name: String = null,
                           table_name: String = null,
                           acks: String = null,
                           product_mode: String = null,
                           hash_column: String = null,
                           advanced_options: JObject = null,
                           extender: ExtenderInfo = null,
                           extract_fields: List[ExtractFieldInfo] = Nil
                          )

case class KafkaAdvancedOptions(
                                 parallelism: Parallelism = null
                               )

case class Parallelism(on_off: Boolean = false,
                       write_parall: Int = 1)